<template>
  <div class="company-list-1">
    <div class="header">
      <div class="prefix"></div>
      <div class="header-title">每日任务耗时分析</div>
    </div>
    <div class="content">
      <div style="width: 460px; height: 300px">
        <MyEchart :option="dataSource"></MyEchart>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted, onUnmounted, watchEffect } from 'vue'
import MyEchart from '@/components/echarts/MyCharts2.vue'

const props = defineProps({
  info: {
    type: Array,
    default: () => []
  }
})

const dataSource = ref()

watchEffect(() => {
  const xdate = []
  const SHIPMENT_DATA = []

  props.info.forEach((item) => {
    xdate.push(item.time)
    SHIPMENT_DATA.push(item.count)
  })
  dataSource.value = {
    tooltip: {
      trigger: 'axis' // 坐标轴触发
    },
    xAxis: {
      type: 'category',
      data: xdate
    },
    yAxis: {
      name: '单位: min',
      color: '#fff',
      splitLine: {
        show: true,
        lineStyle: {
          type: 'dashed'
        }
      }
    },
    series: [
      {
        data: SHIPMENT_DATA,
        type: 'bar',
        barMaxWidth: 15,
        itemStyle: {
          //这里设置柱形图圆角 [左上角，右上角，右下角，左下角]
          borderRadius: [50, 50, 0, 0],
          color: {
            type: 'linear',
            x: 0, //右
            y: 0, //下
            x2: 0, //左
            y2: 1, //上
            colorStops: [
              {
                offset: 0,
                color: '#52c1e7' // 0% 处的颜色
              },
              {
                offset: 0.7,
                color: '#428fd2' // 70% 处的颜色
              },
              {
                offset: 1,
                color: '#3463bf' // 100% 处的颜色
              }
            ]
          }
        }
      }
    ]
  }
})
</script>

<style scoped lang="scss">
@import '@/assets/table.css';

.company-list-1 {
  padding: 10px;
  width: 100%;
  position: relative;
  display: flex;
  flex-direction: column;
  font-size: 16px;

  .header {
    width: 350px;
    height: 50px;
    display: flex;
    align-items: center;
    padding-left: 20px;

    .prefix {
      width: 8px;
      height: 15px;
      background-color: #31a7ff;
    }

    .header-title {
      padding-left: 10px;
    }
  }

  .content {
    flex: 1;
    display: flex;
    justify-content: space-between;
    padding: 0 10px;
  }
}
</style>
